﻿using VisionDesigner.BeadGuide;
using VM.Common.Helper;

namespace Plugin.BeadGuide
{
    [Serializable]
    public class BeadGuideEditModel : NotifyPropertyBase
    {
        public Dictionary<string, string> ParamMap = new Dictionary<string, string>
        {
            { "查找最强边缘", "Best" },
            { "查找第一个边缘", "First" },
            { "查找最后一个边缘", "Last" },
            { "由黑到白边", "Black2White" },
            { "由白到黑边", "White2Black" },
            { "两种类型边", "All" },
        };

        private Dictionary<string, int> _paramInt = new Dictionary<string, int>();
        public Dictionary<string, int> ParamInt
        {
            get { return _paramInt; }
            set { Set(ref _paramInt, value); }
        }

        private Dictionary<string, Array> _paramArray = new Dictionary<string, Array>();
        public Dictionary<string, Array> ParamArray
        {
            get { return _paramArray; }
            set { Set(ref _paramArray, value); }
        }

        private Dictionary<string, object> _paramEnum = new Dictionary<string, object>();
        public Dictionary<string, object> ParamEnum
        {
            get { return _paramEnum; }
            set { Set(ref _paramEnum, value); }
        }

        public BeadGuideEditModel()
        {
            // 整型数据
            ParamInt.Add("CaliperWidth", 5); // 卡尺宽度
            ParamInt.Add("CaliperHeight", 50); // 卡尺高度
            ParamInt.Add("EdgeStrength", 25); // 边缘强度
            ParamInt.Add("HalfKernenlSize", 1); // 边缘过渡宽度

            //  Enum数据
            ParamArray.Add("FindMode", Enum.GetValues(typeof(FindModeEnum)));
            ParamEnum.Add("FindMode", FindModeEnum.查找最强边缘);
            ParamArray.Add("PointPolarity", Enum.GetValues(typeof(PointPolarityEnum)));
            ParamEnum.Add("PointPolarity", PointPolarityEnum.两种类型边);
        }

        public void UpdateParam(CBeadGuideTool cBeadGuideTool)
        {
            // 整型数据
            foreach (var pair in ParamInt)
            {
                string key = pair.Key;
                string value = pair.Value.ToString();
                cBeadGuideTool.SetRunParam(key, value);
            }

            // Enum数据
            foreach (var pair in ParamEnum)
            {
                string key = pair.Key;
                string value = pair.Value.ToString();
                if (ParamMap.ContainsKey(value))
                {
                    cBeadGuideTool.SetRunParam(key, ParamMap[value]);
                }
            }
        }
    }

    /// <summary>
    /// 查找模式
    /// </summary>
    [Serializable]
    public enum FindModeEnum
    {
        查找最强边缘,
        查找第一个边缘,
        查找最后一个边缘
    }

    /// <summary>
    /// 匹配极性模式
    /// </summary>
    [Serializable]
    public enum PointPolarityEnum
    {
        由黑到白边,
        由白到黑边,
        两种类型边
    }

    /// <summary>
    /// 运行模式
    /// </summary>
    [Serializable]
    public enum RunModeEnum
    {
        寻找边缘,
        拟合点
    }

}
